// components/icon/icon.js
const { getSvgIcon } = require("../../utils/svg-icons.js");

Component({
  properties: {
    name: {
      type: String,
      value: "",
    },
    size: {
      type: Number,
      value: 32,
    },
    color: {
      type: String,
      value: "#333333",
    },
  },

  data: {
    svgContent: "",
  },

  lifetimes: {
    attached() {
      this.loadSvgIcon();
    },
  },

  observers: {
    name: function (newVal) {
      this.loadSvgIcon();
    },
    color: function (newVal) {
      this.loadSvgIcon();
    },
    size: function (newVal) {
      this.loadSvgIcon();
    },
  },

  methods: {
    // 加载SVG图标
    loadSvgIcon() {
      const svgContent = getSvgIcon(
        this.data.name,
        this.data.size,
        this.data.color
      );
      this.setData({ svgContent });
    },
  },
});
